﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using SignalR.Server.LogHelper;
using SignalR.Server.WebHubs;
using SignalR.Server.WebHubs.impl;

namespace SignalR.Server.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class NotifyController : ControllerBase
    {
        private readonly IHubContext<NotifyHub> _hubContext;
        private readonly ILogger<NotifyController> _logger;
        public NotifyController(IHubContext<NotifyHub> hubContext,ILogger<NotifyController> logger)
        {
            _hubContext = hubContext;
            _logger = logger;
        }
        [HttpGet]
        public async Task<int> Get()
        {
            _logger.LogInformation("系统通知：ReceiveMessage");
            await _hubContext.Clients.All.SendAsync("ReceiveMessage", "系统通知", $"北京时间{DateTime.Now}");
            return 0;
        }
  
        [HttpGet]
        public  async Task<JsonResult> GetLogMessage()
        {
            var data = ReadHelper.Read();
            await _hubContext.Clients.All.SendAsync("ReceiveLog", data);
            return new JsonResult(0);
        }
    } 
}